﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InsideDL
{
    public class Sheet
    {
        public string SheetName = string.Empty;
        public string StartColumn = string.Empty;
        public string EndColumn = string.Empty;
        public int ShiftColumn = 0;
        
        public List<Section> Sections = null;

        public Sheet(System.Data.DataRow p_row)
        {
            SheetName = p_row["SheetName"].ToString();
            string[] startEnd = p_row["StartEndColumn"].ToString().Split(new char[]{'-'});
            StartColumn = startEnd[0] ;
            EndColumn = startEnd[1];
            //因為自己要算進去，所以要扣掉一
            ShiftColumn = Convert.ToInt16(p_row["ShiftColumn"].ToString()) - 1;
            Sections = new List<Section>();
            string[] sectionCollect = p_row["Sections"].ToString().Split(new char[] { ',' });
            foreach (string str in sectionCollect)
            {
                Sections.Add(new Section(str.Split(new char[] { '-' })));
            }
        }

        protected string GetNextColumn(string p_column)
        {
            char[] chs = p_column.ToCharArray();
            return Convert.ToChar(Convert.ToInt16(chs[0]) + ShiftColumn).ToString();
        }

    
        public string GetThisMonthArea(Section p_section)
        {
            return string.Format("{0}{1}:{2}{3}",
                                StartColumn, p_section.StartRow.ToString()
                                , GetNextColumn(StartColumn)
                                , p_section.EndRow.ToString());
        }

        public string GetLastMonthArea(Section p_section)
        {
            return string.Format("{0}{1}:{2}{3}"
                , EndColumn, p_section.StartRow
                , GetNextColumn(EndColumn)
                , p_section.EndRow.ToString());
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public string GetNewChar(string p_col , int p_pos)
        {
            char[] chs = p_col.ToCharArray();
            return Convert.ToChar(Convert.ToInt16(chs[0]) + p_pos).ToString();
        }
    }
}
